package com.uenpay.im.ui.old.activity.wallet;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.uenpay.im.R;

import java.util.ArrayList;


public class StatementAdapter extends BaseAdapter {

	private LayoutInflater mInflater;
	private ArrayList<PaymentEntity> arrayList = new ArrayList<PaymentEntity>();

	public StatementAdapter(Context _Context,
			ArrayList<PaymentEntity> _ArrayList) {
		mInflater = LayoutInflater.from(_Context);
		arrayList = _ArrayList;
	}

	public void addData(ArrayList<PaymentEntity> _ArrayList) {
		arrayList.addAll(_ArrayList);
		notifyDataSetChanged();
	}

	public void setData(ArrayList<PaymentEntity> _ArrayList) {
		arrayList = _ArrayList;
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return arrayList.size();
	}

	@Override
	public Object getItem(int arg0) {
		return arrayList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		RedViewHolder holder = null;
		PaymentEntity redPaymentEntity = arrayList.get(arg0);
		if (arg1 == null) {
			holder = new RedViewHolder();
			arg1 = mInflater.inflate(R.layout.item_statement_layout, arg2,
					false);
			holder.moneyTv = (TextView) arg1.findViewById(R.id.money_tv);
			holder.dateTv = (TextView) arg1.findViewById(R.id.date_tv);
			holder.titleTv = (TextView) arg1.findViewById(R.id.title_tv);
			arg1.setTag(holder);
		} else {
			holder = (RedViewHolder) arg1.getTag();
		}
		holder.dateTv.setText(redPaymentEntity.createtime);
		if (!TextUtils.isEmpty(redPaymentEntity.amount)) {
			if (redPaymentEntity.amount.startsWith("-")) {
				holder.moneyTv.setText(redPaymentEntity.amount);
//				holder.moneyTv.setTextColor(mContext.getResources().getColor(
//						R.color.the_color_black));
			} else {
				holder.moneyTv.setText("+" + redPaymentEntity.amount);
//				holder.moneyTv.setTextColor(mContext.getResources().getColor(
//						R.color.CLR02C70C));
			}
		}
		holder.titleTv.setText(redPaymentEntity.subject);
		return arg1;
	}

	private class RedViewHolder {
		private TextView titleTv, dateTv, moneyTv;
	}

}
